// pages/orderTickets/orderTickets.js
const util = require("../../utils/util.js");
const dataUtil = require("../../utils/dataUtil.js");
import Toast from '../../dist/toast/toast';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    hotelData:{},
    cloudUrl:app.globalData.cloudUrl,
    isPayDetailShow:false,
    timeStr:"",
    inStr:"",
    outStr:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: "订单详情"
    })

    var info1 = JSON.parse(options.data);
    console.log("orderHotels.js,",info1);
    const app = getApp();
    const list = app.globalData.hotelRoomList;
    var data = null;
    for(var i=0; i<list.length; i++){
      console.log("list[i].id="+list[i].id+",info1.id="+info1.id+",equal="+(list[i].id == info1.id));
      if(list[i].id == info1.id){
        data = list[i];
        break;
      }
    }
    const str = this.getDateStr2(info1.time);
    const str1 = this.getDateStr2(info1.rangeDate[0]);
    const str2 = this.getDateStr2(info1.rangeDate[1]);
    console.log("hotelData,",data);//
    this.setData({info:info1,hotelData:data,timeStr:str,inStr:str1,outStr:str2});
  },
  onPayDetailClick(e){
    this.setData({isPayDetailShow:false});
  },
  getDateStr2(time){
    var date = new Date(time);
    var year = date.getFullYear();
    if(year < 10){ year = "0"+year; }
    var month = date.getMonth() + 1;
    if(month < 10){ month = "0"+month; }
    var day = date.getDate();
    if(day < 10){ day = "0"+day; }
    return year + "-" + month + "-" + day;
  },
  onPayDetail(e){
    console.log(this.data.isPayDetailShow)//
    this.setData({
      isPayDetailShow:!this.data.isPayDetailShow
    });
  },
  onCancel(e){
    dataUtil.deleteHotelOrder(this.data.info, this.onCallBack);
  },
  onCallBack(result){
    wx.navigateBack({
      delta: 1
    })
  },
  onPay(e){
    Toast("暂未开通微信支付");
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})